package cn.edu.swpu.cins.u_chain.frontend.controller.user;

import cn.edu.swpu.cins.u_chain.frontend.entity.dto.ResultData;
import cn.edu.swpu.cins.u_chain.frontend.entity.dto.user.company.CompanyDetail;
import cn.edu.swpu.cins.u_chain.frontend.entity.dto.user.company.CompanyInfo;
import cn.edu.swpu.cins.u_chain.frontend.service.user.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("UChain/user/company")
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    //@ExceptionHandler({CompanyException.class, SQLException.class, RuntimeException.class})
    public ResultData handleException(Exception e) {
        return new ResultData(false, e.getMessage());
    }

    @PostMapping("addInfo")
    public ResultData addCompanyInfo(@RequestBody CompanyInfo companyInfo) {
        companyService.addInfo(companyInfo);
        return new ResultData(true, "添加成功");
    }

    @GetMapping("getInfo")
    public ResultData getCompanyInfo(@RequestParam int userId) {
        CompanyDetail detail = companyService.selectComDetail(userId);
        return new ResultData(true, "企业用户资料", detail);
    }


}
